package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auth: cdz
 * @Desc:
 * @Date: 2023/3/15 18:01
 */
@RestController
@RequestMapping("/admin/order")
@Api(tags = "订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 功能描述: 分页查询订单
     *
     * @param queryDTO
     * @return : com.sky.result.Result<com.sky.result.PageResult>
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("分页查询订单")
    public Result<PageResult> page(OrdersPageQueryDTO queryDTO) {
        PageResult pageResult = orderService.page(queryDTO);
        return Result.success(pageResult);
    }

    /**
     * 功能描述:  各个状态的订单数量统计
     *
     * @return : com.sky.result.Result
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO statisticsVO = orderService.statistic();
        return Result.success(statisticsVO);
    }

    /**
     * 功能描述: 查询订单详情
     *
     * @param id
     * @return : com.sky.result.Result<com.sky.vo.OrderVO>
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO orderVO = orderService.findDetailsById(id);
        return Result.success(orderVO);
    }

    /**
     * 功能描述: 派送订单
     *
     * @param id
     * @return : com.sky.result.Result
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 功能描述: 拒绝订单
     *
     * @return : com.sky.result.Result
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 功能描述: 取消订单
     *
     * @param ordersCancelDTO
     * @return : com.sky.result.Result
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 功能描述: 接单
     *
     * @return : com.sky.result.Result
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 功能描述: 完单
     *
     * @return : com.sky.result.Result
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完单")
    public Result complete(@PathVariable("id") long id) {
        orderService.complete(id);
        return Result.success();
    }
}
